package com.aggron.concurrency.lock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author LR2SD
 * @description condition测试类
 * @date 2018-06-13 20:52
 */
@Slf4j
public class LockExample4 {

    public static void main(String [] args){
        Lock lock=new ReentrantLock();
        Condition condition=lock.newCondition();

        new Thread(()->{
            try {
                lock.lock();
                log.info("wait sigal");
                condition.await();
            }catch (Exception e){

            }finally {
               lock.unlock();
            }
            log.info("get sigal");

        }).start();

        new Thread(()->{
            try {
                lock.lock();
                log.info("hi  sigal");
                Thread.sleep(1000);
            }catch (Exception e){

            }finally {
                lock.unlock();
            }
            condition.signalAll();


            log.info("send sigal");

        }).start();
    }
}
